package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yuetong.business.domain.YtPlaceInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtElevatorInfo;
import com.yuetong.business.service.IYtElevatorInfoService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 电梯信息，用于存储电梯的基本信息及其所属场所Controller
 *
 * @author  卓晓君
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/business/elevator")
public class YtElevatorInfoController extends BaseController
{
    @Autowired
    private IYtElevatorInfoService ytElevatorInfoService;

    /**
     * 查询电梯信息，用于存储电梯的基本信息及其所属场所列表
     */
    @PreAuthorize("@ss.hasPermi('business:elevator:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtElevatorInfo ytElevatorInfo)
    {
        startPage();
        List<YtElevatorInfo> list = ytElevatorInfoService.selectYtElevatorInfoList(ytElevatorInfo);
        return getDataTable(list);
    }

    /**
     * 导出电梯信息，用于存储电梯的基本信息及其所属场所列表
     */
    @PreAuthorize("@ss.hasPermi('business:elevator:export')")
    @Log(title = "导出电梯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtElevatorInfo ytElevatorInfo)
    {
        List<YtElevatorInfo> list = ytElevatorInfoService.selectYtElevatorInfoList(ytElevatorInfo);
        ExcelUtil<YtElevatorInfo> util = new ExcelUtil<YtElevatorInfo>(YtElevatorInfo.class);
        util.exportExcel(response, list, "电梯信息，用于存储电梯的基本信息及其所属场所数据");
    }

    /**
     * 获取电梯信息，用于存储电梯的基本信息及其所属场所详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:elevator:query')")
    @GetMapping(value = "/{elevatorId}")
    public AjaxResult getInfo(@PathVariable("elevatorId") Long elevatorId)
    {
        return success(ytElevatorInfoService.selectYtElevatorInfoByElevatorId(elevatorId));
    }

    /**
     * 新增电梯信息，用于存储电梯的基本信息及其所属场所
     */
    @PreAuthorize("@ss.hasPermi('business:elevator:add')")
    @Log(title = "新增电梯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtElevatorInfo ytElevatorInfo)
    {
        return toAjax(ytElevatorInfoService.insertYtElevatorInfo(ytElevatorInfo));
    }

    /**
     * 修改电梯信息，用于存储电梯的基本信息及其所属场所
     */
    @PreAuthorize("@ss.hasPermi('business:elevator:edit')")
    @Log(title = "修改电梯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtElevatorInfo ytElevatorInfo)
    {
        return toAjax(ytElevatorInfoService.updateYtElevatorInfo(ytElevatorInfo));
    }

    /**
     * 删除电梯信息，用于存储电梯的基本信息及其所属场所
     */
    @PreAuthorize("@ss.hasPermi('business:elevator:remove')")
    @Log(title = "删除电梯信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{elevatorIds}")
    public AjaxResult remove(@PathVariable Long[] elevatorIds)
    {
        return toAjax(ytElevatorInfoService.deleteYtElevatorInfoByElevatorIds(elevatorIds));
    }

    /**
     * @Remark: * 电梯信息导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YtElevatorInfo> util = new ExcelUtil<YtElevatorInfo>(YtElevatorInfo.class);
        util.importTemplateExcel(response, "电梯数据");
    }

    /**
     * 电梯信息导入
     */
    @Log(title = "电梯信息导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('business:elevator:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YtElevatorInfo> util = new ExcelUtil<YtElevatorInfo>(YtElevatorInfo.class);
        List<YtElevatorInfo> infoList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = "";//userService.importUser(userList, updateSupport, operName);
        return success(message);
    }
}
